/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * uiRootPanel.java
 *
 * Created on Jun 26, 2012, 8:57:00 PM
 */
package taskspydelux;

import java.awt.Component;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author skstudio
 */
public class uiRootPanel extends javax.swing.JPanel {
    JFrame mFrame = null;

    public uiRootPanel() {
        initComponents();
    }

    /** Creates new form uiRootPanel */
    public uiRootPanel(JFrame frame) {
        mFrame = frame;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    public uiChartView getChart() {
        return null;
    }

    public void resetUI() {
        int size = this.getComponentCount();
        for(int ii = 0; ii < size; ii++) {
            Component comp = getComponent(ii);
            uiRootPanel child = (uiRootPanel)comp;

            uiChartView chart = child.getChart();
            if (chart != null) {
                chart.resetUI();
            }
        }
    }

    public void updateLoadingUI(int value, int rid) {
        TaskSpyApp app = (TaskSpyApp) mFrame;
        app.jb.setString(String.format("Loading record %d", rid));
        app.jb.setValue(value);
    }

    public void reportException(Exception e) {
        StringBuilder sb = new StringBuilder();
        sb.append(e.toString());
        sb.append("\n\n");
        
        StackTraceElement[] ste = e.getStackTrace();
        for(StackTraceElement elm : ste) {
            sb.append(elm.toString());
            sb.append("\n");
        }

        JOptionPane.showMessageDialog(
                mFrame,
                sb.toString(),
                "Exception",
                JOptionPane.ERROR_MESSAGE);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
